/**
  ETFRoot project, Anyang Normal University && IMP-CAS
  \class ETF3DTrack
  \brief class for a 3D track
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2021-11-02
  \date 2021-11-25 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date         <th>Author      <th>Description                   </tr>
  <tr>  <td>2021-11-02   <td>Asia Sun    <td>file created                  </tr>
  </table>

  \copyright Copyright (c) 2021 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#ifndef ETF3DTrack_h
#define ETF3DTrack_h

#include <map>
#include <vector>
#include <string>
#include <array>
#include <TNamed.h>
#include "ETFVDC.h" // contain the definition of enum class TrackType

class ETFTrack;

using std::vector;
using std::string;
using std::array;
using std::map;

class ETF3DTrack : public TNamed{
public:
  ETF3DTrack();
  ETF3DTrack(const ETF3DTrack &trk);
  ETF3DTrack &operator=(const ETF3DTrack &trk);
  virtual ~ETF3DTrack();

  const map<TrackType, ETFVTrack *> &GetTrackMap() const{ return fTracks; }
  const double *GetXMiss3D() const{ return fXMiss3D; }
  virtual void Print(); ///< print the track info
  double GetK1(){ return fK1; }
  double GetB1(){ return fB1; }
  double GetK2(){ return fK2; }
  double GetB2(){ return fB2; }

  void Initialize();
  void SetTrack(TrackType type, ETFVTrack *trk);
  void SetK1B1(double k1, double b1){ fK1 = k1; fB1 = b1; }
  void SetK2B2(double k2, double b2){ fK2 = k2; fB2 = b2; }
  void SetXMiss3D(double *p);
  /// number the track, set the name&title for the track
  virtual void SetId(int id);

  void GetHitPos(const string &d, double &lx, double &ly) const;
  double GetHitPosX(const string &d) const;
  double GetHitPosY(const string &d) const;
  const map<string, double> &GetHitPosXMap() const{ return fHitPosXMap; }
  const map<string, double> &GetHitPosYMap() const{ return fHitPosYMap; }
  virtual void SetHitPos(const string &d, double lx, double ly);
  virtual void UpdateHitPos(ETFDetector *d); ///< assign hit pos at det's central plane

  ClassDef(ETF3DTrack, 1);

protected:
  map<TrackType, ETFVTrack *> fTracks; //! ///< the projections of the 3D track
  double fK1, fB1, fK2, fB2; ///< slopes and intercepts in xOz (k1,b1) and yOz (k2,b2) plane
  double fXMiss3D[3]; ///< 3D track coincidence test at z coordinates of the three DCs
  map<string, double> fHitPosXMap; ///< map<det, pos> hit X position at each det (local frame)
  map<string, double> fHitPosYMap; ///< map<det, pos> hit Y position at each det (local frame)
};

#endif
